package it.unibo.refolding.pico;

import it.unibo.refolding.common.LinearFunction;

import java.awt.geom.Point2D;

import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;


public class ZLsbDeflectionLsbPoint {

	public final double zLsb;
	public final double deflectionLsb;
	
	public ZLsbDeflectionLsbPoint(double zLsb, double deflectionLsb) {
		this.zLsb = zLsb;
		this.deflectionLsb = deflectionLsb;
	}
	
	public LinearFunction linearFunctionWithSlope(double slope) {
		return LinearFunction.lineWithSlopeThroughPoint(slope, toPoint2D());
	}

	public Point2D.Double toPoint2D() {
		return new Point2D.Double(zLsb, deflectionLsb);
	}

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(zLsb).append(deflectionLsb).toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof ZLsbDeflectionLsbPoint)) {
			return false;
		}
		ZLsbDeflectionLsbPoint other = (ZLsbDeflectionLsbPoint) obj;
		return zLsb == other.zLsb && deflectionLsb == other.deflectionLsb;
	}

	public ZLsbDeflectionLsbPoint withDeflectionLsb(double defLsb) {
		return new ZLsbDeflectionLsbPoint(zLsb, defLsb);
	}
}
